<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- K 和数对的最大数目 -->
    <script>
      var max = function (nums, k) {
        res = 0
        nums = nums.filter(a => a < k)
        for (let i = 0; i < nums.length; i++) {
          if (nums[i] !== null) {
            let other = k - nums[i]
            nums[i] = null
            let idx = nums.indexOf(other)
            if (idx > -1) {
              nums[idx] = null
              res++
            }
          }
        }
        return res
      }
      // console.log(max([1, 2, 3, 4], 5))
      console.log(max([3, 1, 3, 4, 3], 6))
    </script>
  </body>
</html>
